import scala.collection.mutable
import scala.io.{Source, StdIn}

object Count {

  def init(path: String): collection.mutable.Map[String, mutable.Map[String, Int]] = {
    val lines = Source.fromFile(path).mkString("").split("\n")
    val all: collection.mutable.Map[String, mutable.Map[String, Int]] = collection.mutable.Map()
    for (line <- lines) {
      val a = line.split(",")
      val province: String = a(2)
      val provider: String = a(4)
      if (!all.contains(province)) {
        all += province -> collection.mutable.Map(provider -> 1)
      }
      else if (all(province).contains(provider)) all(province)(provider) += 1
      else all(province) += provider -> 1
    }
    all
  }

  def main(args: Array[String]): Unit = {
    val result: mutable.Map[String, mutable.Map[String, Int]] = init("data/2016phonelocation.txt")
    var province: String = null
    do {
      province = StdIn.readLine()
      println(result(province).mkString("\t"))
    } while (province != null)
  }
}

/**
 * 用户输入任意省份，输出这个省份号码段的个数，电信、移动、联通各占多少个
 */
